package com.kele.basic;

/**
 * @author chunhui.li
 * @date 2022/1/21 10:48
 * @Description
 * @ClassName CurrentTest
 */
public class CurrentTest implements Runnable{

    public  int num=0;

    public static void main(String[] args) throws InterruptedException {
        CurrentTest currentTest = new CurrentTest();

        Thread thread1 =new Thread(currentTest);
        Thread thread2 =new Thread(currentTest);
        Thread thread3 =new Thread(currentTest);
        Thread thread4 =new Thread(currentTest);
        Thread thread5 =new Thread(currentTest);

        thread1.start();
        thread2.start();
        thread3.start();
        thread4.start();
        thread5.start();
        thread1.join();
        thread2.join();
        thread3.join();
        thread4.join();
        thread5.join();
        System.out.println(currentTest.num);
    }
    public synchronized void incr(){
        for (int i = 0; i < 2000; i++) {
            num++;
        }
//        System.out.println(num);
//        System.out.println(Thread.currentThread().getName());
    }

    @Override
    public void run() {
        incr();
    }

}
